<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>订单管理</title>
	<!-- ICON -->
	<link href="/frame/images/meatball.ico" type="image/ico" rel="shortcut icon">
	<!-- CSS -->
	<link rel="stylesheet" href="/lib/layuiadmin/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/lib/layuiadmin/css/admin.css" media="all" />
    <style>
        .layui-form-pane .layui-form-label{
            width: 150px;
        }
        .layui-form-pane .layui-input-block {
            margin-left: 150px;
        }
        /*.layui-table-cell {*/
        /*    !* 防止下拉框的下拉列表被隐藏---必须设置--- *!*/
        /*    overflow: visible !important;*/
        /*    line-height: 15px !important;*/
        /*    vertical-align: middle;*/
        /*    !*height: auto;*!*/
        /*    !*overflow: visible;*!*/
        /*    text-overflow: inherit;*/
        /*    white-space: normal;*/
        /*}*/

        /* 使得下拉框与单元格刚好合适 */
        /*td .layui-form-select{*/
        /*    margin-top: -10px;*/
        /*    margin-left: -15px;*/
        /*    margin-right: -15px;*/
        /*}*/

    </style>
</head>
<body layadmin-themealias="default">
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body">
			<div class="layui-row">
                <div class="layui-col-md2">
                    <!--<form class="layui-form" style="float: left;">-->
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-warm" lay-submit lay-filter="addBtn" title="新增">
                            <i class="layui-icon">&#xe61f;</i> 新增
                        </button>
                    </div>
                </div>
				<div class="layui-col-md10">
					<form class="layui-form" id="queryForm" style="float: right;">

                        <div class="layui-inline">
                            <input type="text" id="ddsj" name="ddsj" title="订单时间" placeholder="请输入订单时间" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <select name="zt" title="订单状态">
                                <option value="">全部</option>
                                <option value="0">已申请</option>
                                <option value="1">已签订合同</option>
                                <option value="2">已完成</option>
                            </select>
                        </div>
                        <button class="layui-btn" lay-submit lay-filter="query">
                            <i class="layui-icon">&#xe615;</i> 查询
                        </button>

					</form>
				</div>
			</div>
			<hr class="layui-bg-gray">
			<div class="layui-row">
				<div class="layui-col-md12">
					<!-- 表格 -->
					<table id="table" lay-filter="table"></table>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 操作 -->
<script type="text/html" id="operationBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit_threeorder">设置</a>
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<!--  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>


<!-- 新增 -->
<script type="text/html" id="addForm">
    <form class="layui-form layui-form-pane">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-row">
                    <div class="layui-col-md12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="ddbm" autocomplete="off" placeholder="请输入订单编码" class="layui-input" value="{{d.ddbm ||''}}" lay-verify="required">
                            </div>
                        </div>
<!--                        <div class="layui-form-item">-->
<!--                            <label class="layui-form-label">订单时间</label>-->
<!--                            <div class="layui-input-block">-->
<!--                                <input type="text" name="ddsj" autocomplete="off" placeholder="请输入订单时间" class="layui-input" value="{{d.ddsj ||''}}" lay-verify="required">-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-form-item">
                            <label class="layui-form-label">编码</label>
                            <div class="layui-input-block">
                                <input type="text" name="bm" autocomplete="off" placeholder="请输入编码" class="layui-input" value="{{d.bm ||''}}" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">数量</label>
                            <div class="layui-input-block">
                                <input type="text" name="sl" autocomplete="off" placeholder="请输入数量" class="layui-input" value="{{d.sl ||''}}" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">单价</label>
                            <div class="layui-input-block">
                                <input type="text" name="dj" autocomplete="off" placeholder="请输入单价" class="layui-input" value="{{d.dj ||''}}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">重量</label>
                            <div class="layui-input-block">
                                <input type="text" name="zl" autocomplete="off" placeholder="请输入重量" class="layui-input" value="{{d.zl ||''}}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">签订合同时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="qdhtsj" autocomplete="off" placeholder="请输入签订合同时间" class="layui-input" value="{{d.qdhtsj ||''}}">

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">付款养殖户时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="fkyzhsj" autocomplete="off" placeholder="请输入付款养殖户时间" class="layui-input" value="{{d.fkyzhsj ||''}}">

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">司机姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="xm" autocomplete="off" placeholder="请输入司机姓名" class="layui-input" value="{{d.xm ||''}}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="sjh" autocomplete="off" placeholder="请输入手机号" class="layui-input" value="{{d.sjh ||''}}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">身份账号</label>
                            <div class="layui-input-block">
                                <input type="text" name="sfzh" autocomplete="off" placeholder="请输入身份账号" class="layui-input" value="{{d.sfzh ||''}}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">付款时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="fksj" autocomplete="off" placeholder="请输入付款时间" class="layui-input" value="{{d.fksj ||''}}">

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <!--                            <input type="text" name="lx" autocomplete="off" placeholder="请输入类型" class="layui-input" value="{{d.lx ||''}}">-->
                                <select name="zt" title="状态">
                                    <option value="0" {{d.zt == 0 ? 'selected ' : ''}}>已申请</option>
                                    <option value="1" {{d.zt == 1 ? 'selected ' : ''}}>已签订合同</option>
                                    <option value="2" {{d.zt == 2 ? 'selected ' : ''}}>已完成</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">交流详情</label>
                            <div class="layui-input-block">
                                <input type="text" name="wz" autocomplete="off" placeholder="请输入交流详情" class="layui-input" value="{{d.wz ||''}}">
                            </div>
                        </div>

                    </div>
                    <div class="hidden-attribute">
                        <button class="layui-btn submit" lay-submit="" lay-filter="add">新增</button>
                        <button class="layui-btn reset" type="reset">重置</button>
                    </div>
                </div>
                <input class="hidden-attribute" name="id" value="{{d.id}}" title="ID">
            </div>
        </div>
    </form>
</script>


<!-- 详情 -->
<script type="text/html" id="view">
<table class="layui-table" style="width: 680px; margin: 10px 10px 0px 10px;">
	<tr><td class="table-td-title">订单编号</td><td width="465">{{d.ddbm ||''}}</td></tr>
	<tr><td class="table-td-title">编码</td><td width="465">{{d.bm ||''}}</td></tr>
	<tr><td class="table-td-title">订单时间</td><td width="465">{{d.ddsj ||''}}</td></tr>
	<tr><td class="table-td-title">屠宰场用户</td><td width="465">{{d.czcUser?d.czcUser.xm:''}}</td></tr>
	<tr><td class="table-td-title">养殖户</td><td width="465">{{d.yzhUser?d.yzhUser.xm:''}}</td></tr>
	<tr><td class="table-td-title">数量</td><td width="465">{{d.sl ||''}}</td></tr>
	<tr><td class="table-td-title">单价</td><td width="465">{{d.dj ||''}}</td></tr>
	<tr><td class="table-td-title">重量</td><td width="465">{{d.zl ||''}}</td></tr>
	<tr><td class="table-td-title">签订合同时间</td><td width="465">{{d.qdhtsj ||''}}</td></tr>
	<tr><td class="table-td-title">付款养殖户时间</td><td width="465">{{d.fkyzhsj ||''}}</td></tr>

    <tr><td class="table-td-title">司机姓名</td><td width="465">{{d.xm ||''}}</td></tr>
    <tr><td class="table-td-title">手机号</td><td width="465">{{d.sjh ||''}}</td></tr>
    <tr><td class="table-td-title">身份账号</td><td width="465">{{d.sfzh ||''}}</td></tr>
    <tr><td class="table-td-title">付款时间</td><td width="465">{{d.fksj ||''}}</td></tr>
    <tr><td class="table-td-title">状态</td><td width="465">
        {{d.zt == 0 ? '已申请 ' : ''}}
        {{d.zt == 1 ? '已签订合同 ' : ''}}
        {{d.zt == 2 ? '已完成 ' : ''}}
    </td>
    </tr>
    <tr><td class="table-td-title">交流详情</td><td width="465">
        <a href="{{d.wz ||''}}">{{d.wz ||''}}</a>
        </td></tr>
</table>

<br>
</script>

<!-- 编辑 -->
<script type="text/html" id="editForm">
<form class="layui-form layui-form-pane">
	<div class="layui-card">
		<div class="layui-card-body">
			<div class="layui-row">
				<div class="layui-col-md12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">订单编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="ddbm" autocomplete="off" placeholder="请输入订单编码" class="layui-input" disabled value="{{d.ddbm ||''}}" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">订单时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="ddsj" autocomplete="off" placeholder="请输入订单时间" class="layui-input" disabled value="{{d.ddsj ||''}}" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">编码</label>
                        <div class="layui-input-block">
                            <input type="text" name="bm" autocomplete="off" placeholder="请输入编码" class="layui-input" value="{{d.bm ||''}}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">数量</label>
                        <div class="layui-input-block">
                            <input type="text" name="sl" autocomplete="off" placeholder="请输入数量" class="layui-input" value="{{d.sl ||''}}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">单价</label>
                        <div class="layui-input-block">
                            <input type="text" name="dj" autocomplete="off" placeholder="请输入单价" class="layui-input" value="{{d.dj ||''}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">重量</label>
                        <div class="layui-input-block">
                            <input type="text" name="zl" autocomplete="off" placeholder="请输入重量" class="layui-input" value="{{d.zl ||''}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">签订合同时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="qdhtsj" autocomplete="off" placeholder="请输入签订合同时间" class="layui-input" value="{{d.qdhtsj ||''}}">

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">付款养殖户时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="fkyzhsj" autocomplete="off" placeholder="请输入付款养殖户时间" class="layui-input" value="{{d.fkyzhsj ||''}}">

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">司机姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="xm" autocomplete="off" placeholder="请输入司机姓名" class="layui-input" value="{{d.xm ||''}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-block">
                            <input type="text" name="sjh" autocomplete="off" placeholder="请输入手机号" class="layui-input" value="{{d.sjh ||''}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">身份账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="sfzh" autocomplete="off" placeholder="请输入身份账号" class="layui-input" value="{{d.sfzh ||''}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">付款时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="fksj" autocomplete="off" placeholder="请输入付款时间" class="layui-input" value="{{d.fksj ||''}}">

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
<!--                            <input type="text" name="lx" autocomplete="off" placeholder="请输入类型" class="layui-input" value="{{d.lx ||''}}">-->
                            <select name="zt" title="状态">
                                <option value="0" {{d.zt == 0 ? 'selected ' : ''}}>已申请</option>
                                <option value="1" {{d.zt == 1 ? 'selected ' : ''}}>已签订合同</option>
                                <option value="2" {{d.zt == 2 ? 'selected ' : ''}}>已完成</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">交流详情</label>
                        <div class="layui-input-block">
                            <input type="text" name="wz" autocomplete="off" placeholder="请输入交流详情" class="layui-input" value="{{d.wz ||''}}">
                        </div>
                    </div>

				</div>
				<div class="hidden-attribute">
					<button class="layui-btn submit" lay-submit="" lay-filter="update">新增</button>
					<button class="layui-btn reset" type="reset">重置</button>
				</div>
			</div>
			<input class="hidden-attribute" name="id" value="{{d.id}}" title="ID">
		</div>
	</div>
</form>
</script>


<!-- 编辑 -->
<script type="text/html" id="edit_treeorder_Form">
    <form class="layui-form layui-form-pane">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-row">
                    <div class="layui-col-md12">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <button class="layui-btn" lay-submit lay-filter="selectUserA">选择A养殖场会员</button>
                                <input type="hidden" id="aid" name="aid" autocomplete="off" class="layui-input" disabled value="{{d.aid ||''}}">
                                <input type="hidden" id="azzh" name="azzh" autocomplete="off" class="layui-input" disabled value="{{d.azzh ||''}}" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">姓名</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="axm" name="axm" autocomplete="off" class="layui-input" disabled value="{{d.axm ||''}}" readonly="readonly">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">手机号</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="asj" name="asj" autocomplete="off" class="layui-input" disabled value="{{d.asj ||''}}" readonly="readonly">
                                </div>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <button class="layui-btn" lay-submit lay-filter="selectUserB">选择B管理员会员</button>
                                <input type="hidden" id="bid" name="bid" autocomplete="off" class="layui-input" disabled value="{{d.bid ||''}}">
                                <input type="hidden" id="bzzh" name="bzzh" autocomplete="off" class="layui-input" disabled value="{{d.bzzh ||''}}" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">姓名</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="bxm" name="bxm" autocomplete="off" class="layui-input" disabled value="{{d.bxm ||''}}" readonly="readonly">
                                </div>
                                <label class="layui-form-label">B->A 预付金额</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="ba_yfje" name="ba_yfje" autocomplete="off" class="layui-input" value="{{d.ba_yfje ||''}}">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">手机号</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="bsj" name="bsj" autocomplete="off" class="layui-input" disabled value="{{d.bsj ||''}}" readonly="readonly">
                                </div>
                                <label class="layui-form-label">B->A 尾付金额</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="ba_wfje" name="ba_wfje" autocomplete="off" class="layui-input" value="{{d.ba_wfje ||''}}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <button class="layui-btn" lay-submit lay-filter="selectUserC">选择C担保方会员</button>
                                <input type="hidden" id="cid" name="cid" autocomplete="off" class="layui-input" disabled value="{{d.cid ||''}}">
                                <input type="hidden" id="czzh" name="czzh" autocomplete="off" class="layui-input" disabled value="{{d.czzh ||''}}" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">姓名</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="cxm" name="cxm" autocomplete="off" class="layui-input" disabled value="{{d.cxm ||''}}" readonly="readonly">
                                </div>
                                <label class="layui-form-label">C->B 预付金额</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="cb_yfje" name="cb_yfje" autocomplete="off" class="layui-input" value="{{d.cb_yfje ||''}}">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">手机号</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="csj" name="csj" autocomplete="off" class="layui-input" disabled value="{{d.csj ||''}}" readonly="readonly">
                                </div>
                                <label class="layui-form-label">C->B 尾付金额</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="cb_wfje" name="cb_wfje" autocomplete="off" class="layui-input" value="{{d.cb_wfje ||''}}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <button class="layui-btn" lay-submit lay-filter="selectUserD">选择D经销商会员</button>
                                <input type="hidden" id="did" name="did" autocomplete="off" class="layui-input" disabled value="{{d.did ||''}}">
                                <input type="hidden" id="dzzh" name="dzzh" autocomplete="off" class="layui-input" disabled value="{{d.dzzh ||''}}" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">姓名</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="dxm" name="dxm" autocomplete="off" class="layui-input" disabled value="{{d.dxm ||''}}" readonly="readonly">
                                </div>
                                <label class="layui-form-label">D->C 预付金额</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="dc_yfje" name="dc_yfje" autocomplete="off" class="layui-input" value="{{d.dc_yfje ||''}}">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:80px">手机号</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="dsj" name="dsj" autocomplete="off" class="layui-input" disabled value="{{d.dsj ||''}}" readonly="readonly">
                                </div>
                                <label class="layui-form-label">D->C 尾付金额</label>
                                <div class="layui-input-inline" style="width:150px">
                                    <input type="text" id="dc_wfje" name="dc_wfje" autocomplete="off" class="layui-input" value="{{d.dc_wfje ||''}}">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hidden-attribute">
                        <button class="layui-btn submit" lay-submit="" lay-filter="update_suborder">保存</button>
                        <button class="layui-btn reset" type="reset">重置</button>
                    </div>
                </div>
                <input class="hidden-attribute" name="ddbm" value="{{d.ddbm}}" title="ddbm">
            </div>
        </div>
    </form>
</script>


<!-- JavaScript -->
<script type="text/javascript" src="/lib/layuiadmin/layui/layui.js"></script>

<script type="text/javascript" th:inline="none">
layui.config({
	base: '/lib/layuiadmin/' //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['index', 'upload'], function() {
	var table = layui.table,
		form = layui.form,
		laydate = layui.laydate,
		upload = layui.upload,
		element = layui.element,
		laytpl = layui.laytpl,
		$ = layui.jquery,
		// $addBtn = $('#addBtn'),
		$queryForm = $('#queryForm'),
		layerIndex = 1;

    laydate.render({
        elem: '#ddsj' //指定元素
    });
	// 绘制表格
	table.render({
// 		id: 'table',
		elem: '#table',
		url: '/pig/order/table',
		page: true, // 开始分页/pig/user
		// cellMinWidth: 80, // 定义全局最小宽度
		request: {
			pageName: 'offset'
		},
		response: {
            statusCode: 10000
          // countName: 'total', //数据总数的字段名称，默认：count
          // dataName: 'list' //数据列表的字段名称，默认：data
		},
		cols: [[
			{type: 'numbers', title: '序号'},
			{field:'ddbm', title: '订单编码',width:80,hide:true},
			{field:'bm', title: '订单编码',width:100, sort: true},
			{field:'ddsj', title: '订单时间', width:200,align:'center'},
			{field:'czcbm', title: '屠宰场用户', width:100,templet:
                    function (d) {
			            if(d.czcUser)return d.czcUser.xm;
                        return "";
                    }
                    },
			{field:'yzhbm', title: '养殖户', width:100,templet:
                    function (d) {
                        if(d.yzhUser)return d.yzhUser.xm;
                        return "";
                    }},
			{field:'sl', title: '数量', width:60,align:'center'},
			{field:'dj', title: '单价', width:60,align:'center'},
			{field:'zl', title: '重量', width:80,align:'center'},
			{field:'qdhtsj', title: '签订合同时间', width:200,align:'center'},
			{field:'fkyzhsj', title: '付款养殖户时间', width:200,align:'center'},
			{field:'xm', title: '司机姓名', width:80},
			{field:'sjh', title: '手机号', width:150,align:'center'},
			{field:'sfzh', title: '身份账号', width:200},
			{field:'fksj', title: '付款时间', width:200,align:'center'},
			{field:'zt', title: '状态',align:'center', width:150,templet:
                    function (d) {
                        if (d.zt == 0) {
                            return "已申请";
                        } else if (d.zt == 1) {
                            return "已签订合同";
                        } else if (d.zt == 2) {
                            return "已完成";
                        }
                        return "";
                    }

                },
            {field:'wz', title: '交流详情', width:200},

			{fixed: 'right', align:'center', width: 180, toolbar: '#operationBar'}
		]]
	});
	//监听工具条
	table.on('tool(table)', function(obj) {
		var data = obj.data,
			$this = $(this),
			getView = view.innerHTML,
			getEdit = editForm.innerHTML;
			get_treeorder_Edit = edit_treeorder_Form.innerHTML;
		if(obj.event === 'detail') {
			$.get('/pig/order/' + data.ddbm, function(res) {
				if(res.code == 403) {
					layer.msg(res.message, {icon: 4});
				} else {
					laytpl(getView).render(res, function(html) {
						popupWin($this.text(), html, false);
					})
				}
			})
		} else if(obj.event === 'del') {
			layer.confirm('真的删除行么', {icon: 3}, function(index) {
				operate('DELETE', {'id': data.ddbm}, false, obj);
				layer.close(index);
			});
		} else if(obj.event === 'edit') {
			$.get('/pig/order/' + data.ddbm, function(res) {
				if(res.status == 403) {
					layer.msg(res.message, {icon: 4});
				} else {
					laytpl(getEdit).render(res, function(html) {
						popupWin($this.text(), html, true);
					});
					rendering();
				}
			})
		} else if(obj.event === 'edit_threeorder') {
            $.get('/pig/order/edit_threeorder/' + data.ddbm, function(res) {
                if(res.status == 403) {
                    layer.msg(res.message, {icon: 4});
                } else {
                    laytpl(get_treeorder_Edit).render(res, function(html) {
                        popupWin($this.text(), html, true);
                    });
                    rendering();
                }
            })
        }
	});

	// 搜索条件提示
	$queryForm.find('input').on('mouseover', function() {
		if(typeof($(this).attr('title')) == 'undefined') return;
		layer.tips($(this).attr('title'), this, {tips: 1});
	});

	// 新增
	form.on('submit(addBtn)', function(data) {
		var $this = $(this);
		laytpl(addForm.innerHTML).render(data, function(html) {
			popupWin($this.attr('title'), html, true);
		});
		rendering();
		return false;
	});

	// 新增
	form.on('submit(add)', function(data) {
		var $form = $(this).parents('form');
		operate('POST', data.field, true);
		return false;
	});

	// 更新
	form.on('submit(update)', function(data) {
		var $form = $(this).parents('form');
		var roles = [];
		$form.find('input[name=roles]:checked').each(function() {
			roles.push($(this).val());
		});
		data.field.roles = roles;
		operate('PUT', data.field, true);
		return false;
	});

	// update_suborder
	form.on('submit(update_suborder)', function(data) {
		var $form = $(this).parents('form');
		// var roles = [];
		// $form.find('input[name=roles]:checked').each(function() {
		// 	roles.push($(this).val());
		// });
		// data.field.roles = roles;
        $.ajax({
            url: '/pig/order/suborder',
            type: 'PUT',
            async: true,
            data: data.field,
            success: function(res) {
                if(res.code == 10000) {
                    layer.close(layerIndex);
                    table.reload('table');
                }  else if(res.code == 403) {
                    layer.msg(res.message, {icon: 4});
                } else {
                    layer.msg(res.message, {icon: 5});
                }
            }
        })

		return false;
	});

	// 查询
	form.on('submit(query)', function(data) {
		table.reload('table', {
			where: data.field
		});
		return false;
	});

	// 选择A人员
	form.on('submit(selectUserA)', function(data) {
        layer.open({
            type: 2,
            title:'选择人员',
            area: ['1200px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/pig/order/selectuser/index?user=A'
        });
		return false;
	});

    // 选择B人员
    form.on('submit(selectUserB)', function(data) {
        layer.open({
            type: 2,
            title:'选择人员',
            area: ['1200px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/pig/order/selectuser/index?user=B'
        });
        return false;
    });
    // 选择C人员
    form.on('submit(selectUserC)', function(data) {
        layer.open({
            type: 2,
            title:'选择人员',
            area: ['1200px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/pig/order/selectuser/index?user=C'
        });
        return false;
    });
    // 选择D人员
    form.on('submit(selectUserD)', function(data) {
        layer.open({
            type: 2,
            title:'选择人员',
            area: ['1200px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/pig/order/selectuser/index?user=D'
        });
        return false;
    });


	function operate(ajaxType, data, refresh, delRow) {
		var url = '/pig/order/';
		if(ajaxType == 'DELETE') {
			url = '/pig/order/' + data.id;
		}
		$.ajax({
			url: url,
		    type: ajaxType,
		    async: true,
		    data: data,
		    success: function(res) {
		    	if(res.code == 10000) {
					layer.close(layerIndex);
                    table.reload('table');
                    layer.msg(res.message, {icon: 1});
		    	}  else if(res.code == 403) {
		    		layer.msg(res.message, {icon: 4});
		    	} else {
		    		layer.msg(res.message, {icon: 5});
		    	}
		    }
		})
	}

	//渲染弹框
	function popupWin(title, content, showBtn) {
		layerIndex = layer.open({
			id: 'meatball',
			type: 1, //Page层类型
			area: '700px', //['700px', '480'],
			maxWidth: 1000,
			maxHeight: 800,
			title: title,
            skin: 'layui-layer-rim', //加上边框
			shade: 0.1, //遮罩透明度
			// maxmin: true, //允许全屏最小化
			anim: 0, //0-6的动画形式，-1不开启
			scrollbar: false, //禁用滚动
			content: content,
			btn: showBtn ? ['<i class="layui-icon layui-icon-ok"></i> 提交', '<i class="layui-icon layui-icon-refresh-1"></i> 重置'] : '',
			yes: function(index, layero) {
				layero.find('form .submit').trigger('click');
				return false;
			},
			btn2: function(index, layero) {
				layero.find('form .reset').trigger('click');
				return false;
			}
		});
        // layer.full(layerIndex);
	}

	// 动态渲染控件
	function rendering() {
		var $form = $('form');
		// 渲染select
		form.render('select');
		// 重新渲染多选框
		form.render('checkbox');
		// // 初始化日期
		// laydate.render({
		// 	elem: '.birthday'
		// });

	}
});

function ChooseValues(user_flag,v) {
    // console.log(user_flag);
    // console.log(v);
    var $ = layui.jquery;
    if (user_flag =='A') {
        $("#aid").val(v.yhbm);
        $("#azzh").val(v.subno);
        $("#axm").val(v.xm);
        $("#asj").val(v.mobile);
        // return v.productName;
    }
    if (user_flag =='B') {
        $("#bid").val(v.yhbm);
        $("#bzzh").val(v.subno);
        $("#bxm").val(v.xm);
        $("#bsj").val(v.mobile);
        // return v.productName;
    }
    if (user_flag =='C') {
        $("#cid").val(v.yhbm);
        $("#czzh").val(v.subno);
        $("#cxm").val(v.xm);
        $("#csj").val(v.mobile);
        // return v.productName;
    }
    if (user_flag =='D') {
        $("#did").val(v.yhbm);
        $("#dzzh").val(v.subno);
        $("#dxm").val(v.xm);
        $("#dsj").val(v.mobile);
        // return v.productName;
    }
}

</script>
</body>
</html>